<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>添加商品-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
		content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="../static/css/font.css">
	<link rel="stylesheet" href="../static/css/weadmin.css">
</head>

<body>
	<div class="weadmin-body" id="add">
		<form class="layui-form" action="http://localhost:8080/admin/goods/add" method="POST" enctype="multipart/form-data" action="/file">
			<div class="layui-form-item">
				<label for="goodsName" class="layui-form-label">
					<span class="we-red">*</span>商品名称
				</label>
				<div class="layui-input-inline">
					<span v-if="goods != null">{{goods.goodsName}}</span>
					<input v-else type="text" id="goodsName" name="goodsName" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="addimg" class="layui-form-label">商品图片</label>
				<div class="layui-input-inline">
					<!-- <input type="file" id="addimg" name="addimg" multiple> -->
					<input id="addimg" name="addimg" ref="addimg" type="file" accept="image/*"
					@change="show($event.target)">
					<img v-if="goods != null" :src="goods.defaultItem.image" id="imgId">
					<img v-else src="" id="imgId">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="price" class="layui-form-label">
					<span class="we-red">*</span>市场价格
				</label>
				<div class="layui-input-inline">
					<span v-if="goods != null">{{goods.price}}</span>
					<input v-else type="text" id="price" name="price" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label for="title" class="layui-form-label">
					<span class="we-red">*</span>商品标题
				</label>
				<div class="layui-input-block">
					<span v-if="goods != null">{{goods.title}}</span>
					<textarea v-else placeholder="请输入内容" id="title" name="title" class="layui-textarea"></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<label for="brand" class="layui-form-label">
					<span class="we-red">*</span>手机品牌
				</label>
				<div class="layui-input-inline" v-if="goods == null">
					<select id="brand" name="brand" class="layui-input">
						<option :value="b.id" v-for="b in brandList">{{b.name}}</option>
					</select>
				</div>
				<div class="layui-input-inline" v-else>
					<select id="brand" name="brand" class="layui-input">
						<option :value="b.id" v-for="b in brandList" v-if="b.id == goods.brandId" selected>{{b.name}}
						</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<div v-for="sp in speciList">
					<label :for="sp.specAliasName" class="layui-form-label">
						<span class="we-red">*</span>{{sp.specName}}
					</label>
					<div class="layui-input-inline" v-if="goods == null">
						<select :id="sp.specAliasName" :name="sp.specAliasName" class="layui-input">
							<option :value="op.id" v-for="op in sp.options">{{op.optionName}}</option>
							<!-- <option v-for="op in sp.options">测试</option> -->
						</select>
					</div>
					<div class="layui-input-inline" v-else-if="sp.specAliasName == 'qzsxt'">
						<span>{{goods.map.qzsxt[0]}}</span>
					</div>
					<div class="layui-input-inline" v-else-if="sp.specAliasName == 'hzsxt'">
						<span>{{goods.map.hzsxt[0]}}</span>
					</div>
					<div class="layui-input-inline" v-else-if="sp.specAliasName == 'spzl'">
						<span>{{goods.map.spzl[0]}}</span>
					</div>
					<div class="layui-input-inline" v-else-if="sp.specAliasName == 'zpcc'">
						<span>{{goods.map.zpcc[0]}}</span>
					</div>
					<div class="layui-input-inline" v-else-if="sp.specAliasName == 'cpu'">
						<span>{{goods.map.cpu[0]}}</span>
					</div>
					<div class="layui-input-inline" v-else-if="sp.specAliasName == 'xtnh'">
						<span>{{goods.map.xtnh[0]}}</span>
					</div>
					<div class="layui-input-inline" v-else-if="sp.specAliasName == 'sim'">
						<span>{{goods.map.sim[0]}}</span>
					</div>
					<div class="layui-input-inline" v-else-if="sp.specAliasName == 'dcrl'">
						<span>{{goods.map.dcrl[0]}}</span>
					</div>
					<div class="layui-input-inline" v-else>
						<select :id="sp.specAliasName" :name="sp.specAliasName" class="layui-input">
							<option :value="op.id" v-for="op in sp.options">{{op.optionName}}</option>
							<!-- <option v-for="op in sp.options">测试</option> -->
						</select>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<label for="itemPrice" class="layui-form-label">
					<span class="we-red">*</span>商品单价
				</label>
				<div class="layui-input-inline">
					<input type="text" id="itemPrice" name="itemPrice" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="itemNum" class="layui-form-label">
					<span class="we-red">*</span>商品库存
				</label>
				<div class="layui-input-inline">
					<input type="text" id="itemNum" name="itemNum" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="L_repass" class="layui-form-label">
				</label>
				<!-- 判断是添加到SPU还是添加到SKU，根据判断结果发送服务器标志 -->
				<input type="hidden" name="server" value="goods" v-if="goods == null">
				<input type="hidden" name="server" value="item" v-else>
				<!-- 发送商品ID -->
				<input type="hidden" name="goodsId" :value="goodsId">
				<button class="layui-btn" lay-filter="add" lay-submit="">添加</button>
			</div>
		</form>
	</div>
	<script src="../lib/layui/layui.js" charset="utf-8"></script>
	<script src="../static/js/admin.js" type="text/javascript" charset="utf-8"></script>
	<script src="../static/js/vue.js"></script>
	<script src="../static/js/axios.js"></script>
	<script src="../static/js/service/product_yh.js"></script>
	<script src="../static/js/controller/product_yh.js"></script>
	<script src="../static/js/controller/CommonUrl_yh.js"></script>
</body>
<script>
	axios.defaults.baseURL = axios_url.baseURL;
	var vueapp = new Vue({
		el: '#add',
		data: {
			brandList: null,			// 品牌列表
			speciList: null,			// 规格列表
			goodsId: null,				// 商品ID
			goods: null,				// 如果没有表示添加商品SPU，如果有则表示添加单品SKU
		},
		methods: {
			// 查询单个商品信息(SPU)
			findGoodsById: product_yh_controller.findGoodsById,
			// 查询所有的商品信息
			findBrandAll: product_yh_controller.findBrandAll,
			// 回显所有的规格
			findSpeciAll: product_yh_controller.findSpeciAll,
			// 商品图片预览
			show: product_yh_service.show,
		},
		created: product_yh_service.createdAdd,
	})
</script>

</html>